<?php
namespace Admin\Controller;
use Think\Controller;
use Org\Util\String;
use Think\Page;
use Think\Upload;
class QuestionController extends CommonController{
	public function index(){
			
		$id=$_GET['id'];
		$ques = M('Question');
			
		$keyword = $_GET['keyword'];
		if ($keyword == NULL){
			$count      = $ques ->count();// 查询满足要求的总记录数
			$Page       = new Page($count,9);// 实例化分页类 传入总记录数和每页显示的记录数
			$show       = $Page->show();// 分页显示输出
			// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			$list = $ques ->limit($Page->firstRow.','.$Page->listRows)->order('created_at desc')->select();
			$this->assign('data',$list);
			$this->assign('page',$show);
		}else {
			$map['truename'] = array('like','%'.$keyword.'%');
			$map['phone'] = array('like','%'.$keyword.'%');
			$map['_logic'] = 'or';
			$where['_complex'] = $map;
			$count      = $ques-> where($where)->count();// 查询满足要求的总记录数
			$parameter=array(
					'keyword'=>$keyword,
			);
			$Page       = new Page($count,6,$parameter);// 实例化分页类 传入总记录数和每页显示的记录数
			$show       = $Page->show();// 分页显示输出
			// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			$list = $ques-> where($where)->limit($Page->firstRow.','.$Page->listRows)->order('created_at desc')->select();
			$this->assign('data',$list);
			$this->assign('page',$show);

			$this->assign('keyword',$keyword);
		}
			
		$this->display('Question/index');
	}


	public function show(){
		$id=$_GET['id'];
		$m=M(CONTROLLER_NAME);
		$arr=$m->find($id);
		$this->assign('data',$arr);
		
		
		$this->display(CONTROLLER_NAME.'/show');
	}
	
	public function del(){
		$m=M('Question');
		$id=$_GET['id'];
		$count=$m->delete($id);
		if($count>0){
			$this->show('del');
		}else{
			$this->show('error');
		}
	}



}
?>
